package com.wgts.wgts.mvp.view.activity.myorder;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.CustomLineaLayoutManager;
import com.wgts.wgts.mvp.view.activity.affrimorder.OrderChildRecycleAdapter;
import com.wgts.wgts.netmodle.resp.MyOrderDetailsEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.umeng.analytics.pro.i.a.c;
import static com.umeng.analytics.pro.i.a.e;
import static com.umeng.analytics.pro.i.a.i;
import static com.umeng.analytics.pro.i.a.n;
import static com.umeng.analytics.pro.i.a.o;

/*
 *
 *     订单详情中的recycleView的adapter
 *   data:2018/9/1017:16
 *
 */public class OrderDetailsRecycleAdapter extends RecyclerView.Adapter<OrderDetailsRecycleAdapter.ViewHold> {
    private OrderChildRecycleAdapter adapter;
    private Context context;
    private List<MyOrderDetailsEntity.Shop> list;
    private String orderType;

    public OrderDetailsRecycleAdapter(Context context, List<MyOrderDetailsEntity.Shop> list, String orderType) {
        this.context = context;
        this.list = list;
        this.orderType = orderType;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.my_order_item_recycle_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, int i) {
        if (orderType != null && orderType.equals("VIP_ORDER")){
            viewHold.messageLy.setVisibility(View.GONE);
        }else {
            viewHold.messageLy.setVisibility(View.VISIBLE);
        }
        if (list.get(i).show){
            viewHold.parentLy.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }else {
            viewHold.parentLy.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
        }
        MoHuGlide.getInstance().glideImgsFormList(viewHold.shopCarStoreImage, list.get(i).sellerIcon, context);
        if (list.get(i).leaveMessage == null || list.get(i).leaveMessage.equals("")){
            viewHold.leaveMessageText.setText("暂无留言");
        }else {
            viewHold.leaveMessageText.setText(list.get(i).leaveMessage);
        }
        viewHold.shopCarStoreName.setText(list.get(i).sellerName);
        //订单recycleView子recycleView的adapter
        CustomLineaLayoutManager customLineaLayoutManager = new CustomLineaLayoutManager(context);
        customLineaLayoutManager.setScrollEnabled(false);
        viewHold.shoppingCarRecycle.setLayoutManager(customLineaLayoutManager);
        adapter = new OrderChildRecycleAdapter(context, list.get(i).products);
        viewHold.shoppingCarRecycle.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.shop_car_store_image)
        ImageView shopCarStoreImage;
        @BindView(R.id.shop_car_store_name)
        TextView shopCarStoreName;
        @BindView(R.id.watch_store_ly)
        LinearLayout watchStoreLy;
        @BindView(R.id.shopping_car_recycle)
        RecyclerView shoppingCarRecycle;
        @BindView(R.id.leave_message_text)
        TextView leaveMessageText;
        @BindView(R.id.parent_ly)
        LinearLayout parentLy;
        @BindView(R.id.message_ly)
        LinearLayout messageLy;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
